package com.game.center.respository;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.game.center.AbstractDao;
import com.game.center.redis.EnumRedisKey;
import com.game.center.entity.Arena;
import com.game.center.mapper.ArenaMapper;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @Author 林道敬
 * @Date 2023-08-24
 * @Description
 **/
@Component
public class ArenaRespository extends AbstractDao<Arena> {

    @Resource
    private ArenaMapper arenaMapper;

    @Override
    protected EnumRedisKey getRedisKey() {
        return EnumRedisKey.ARENA;
    }


    @Override
    protected Class<Arena> getEntityClass() {
        return Arena.class;
    }

    @Override
    protected BaseMapper<Arena> getRepository() {
        return arenaMapper;
    }

    @Override
    public void saveOrUpdateToDB(Arena arena) {
        if(arena != null){
            if(arena.getPlayerId() != null){
                arenaMapper.updateById(arena);
            }else{
                arenaMapper.insert(arena);
            }
        }
    }
}
